/**
 * 
 */
package jvs.peer.io;

import java.io.IOException;
import java.io.OutputStream;

/**
 * @author qiangli
 *
 */
public class PooledOutputStream extends OutputStream {
	private OutputStream out;
	private boolean closed;

	public PooledOutputStream(OutputStream out) {
		this.out = out;
	}

	public void close() throws IOException {
		closed = true;
		out.flush();
	}

	public void flush() throws IOException {
		out.flush();
	}

	public void write(byte[] buffer, int offset, int count) throws IOException {
		out.write(buffer, offset, count);
	}

	public void write(byte[] buffer) throws IOException {
		out.write(buffer);
	}

	public void write(int oneByte) throws IOException {
		out.write(oneByte);
	}

	public void destroy() {
		closed = true;
		if (out == null) {
			return;
		}
		try {
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		out = null;
	}

	public boolean isClosed() {
		return closed;
	}
	
}
